library(ggplot2)
climate <- read.table("clim.txt", header=T)
climate$date <- NULL
clim_month <- aggregate(rain~year+month, data = climate, FUN = sum)
ggplot(clim_month, aes(group=month, x = month, y = rain)) +
geom_boxplot(fill = "cyan") +
scale_y_continuous(name = "Total Monthly Precipitation") +
theme_bw()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
scale_x_continuous(name = "Month", breaks = c(1,2,3,4,5,6,7,8,9,10,11,12))
clim_temp_min <- aggregate(tmin~month+year, data = climate, FUN = mean)
clim_temp_max <- aggregate(tmax~month+year, data = climate, FUN = mean)
clim_temp <- merge(clim_temp_max, clim_temp_min)
ggplot(clim_temp, aes(group= month, x = month)) +
geom_boxplot(aes(y=tmax), fill = "orange") +
geom_boxplot(aes(y=tmin), fill = "lightskyblue1") +
scale_y_continuous(name = "Average Min and Max Temperatures (C)") +
theme_bw()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
scale_x_continuous(name = "Month", breaks = c(1,2,3,4,5,6,7,8,9,10,11,12))
clim_rain <- aggregate(rain~year, data = climate, FUN = sum)
ggplot(clim_rain, aes(y = rain, x = year))+
geom_line(stat = "identity", color = "blue", size = 0.5) +
theme_bw()+
scale_x_continuous(breaks=seq(1940, 2020, by = 5))+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
ylab("Total Annual Precipitation")+
xlab("Year")
## [1] 1 12
clim_season <- aggregate(rain~season+month+year, data = climate, FUN = sum)
ggplot(clim_season, aes(group=season, x = season, y = rain)) +
geom_boxplot(fill = "cyan") +
scale_y_continuous(name = "Precipitation") +
theme_bw()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
scale_x_discrete(name = "Season")
seasonal_rain <- aggregate(rain~year+season, data = climate, FUN = sum)
winter_rain<- subset(seasonal_rain, season == 4)
season_temp <- aggregate(tmax~year+season, data = climate, FUN = mean)
summer_temp <- subset(season_temp, season == 2)
rain_temp <- merge(summer_temp, winter_rain, by = "year")
ggplot(rain_temp, aes(x=rain, y= tmax, group_by(year))) +
geom_point(size=0.8)+
geom_smooth(method=lm, se = FALSE, formula = y ~ x, color = "blue", size = 0.5)+
theme_bw()+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
xlab("Total Winter Precipitation")+
ylab("Mean Temperature")
linear_reg <-lm(rain ~ tmax, data=rain_temp)
summary(linear_reg)
##
## Call:
## lm(formula = rain ~ tmax, data = rain_temp)
##
## Residuals:
## Min 1Q Median 3Q Max
## -402.56 -167.86 -51.86 156.82 1019.19
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 986.37 560.93 1.758 0.0829 .
## tmax -20.48 24.67 -0.830 0.4091
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 263.1 on 73 degrees of freedom
## Multiple R-squared: 0.009355, Adjusted R-squared: -0.004216
## F-statistic: 0.6894 on 1 and 73 DF, p-value: 0.4091